package com.liik.game.util;

public class Vector {
	public float x;
	public float y;
	
	public Vector() {
		this.x = 0;
		this.y = 0;
	}
	
	public Vector(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public void set(float x, float y) {
		this.x = x;
		this.y = y;		
	}
	
	public void set(Vector vector) {
		this.x = vector.x;
		this.y = vector.y;		
	}
	
	public void setDirection(Vector start, Vector end) {
		this.x = end.x - start.x;
		this.y = end.y - start.y;
	}
	
	public void mul(float scale) {
		this.x *= scale;
		this.y *= scale;
	}
	
	public void div(float scale) {
		this.x /= scale;
		this.y /= scale;
	}
	
	public void add(Vector vector) {
		this.x += vector.x;
		this.y += vector.y;
	}

	public void sub(Vector vector) {
		this.x -= vector.x;
		this.y -= vector.y;
	}
	
	public float length() {
		return (float) Math.sqrt(x * x + y * y);
	}
	
	public void normalize() {
		div(length());
	}

	public void left() {
		float tmp = x;
		x = y;
		y = -tmp;
	}
	
	public void right() {
		float tmp = x;
		x = -y;
		y = tmp;
	}
	
	public void reverse() {
		float tmp = x;
		x = y;
		y = tmp;
	}
}
